home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MPW_C
/
SPELL__
/
PCKCHECK.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-03
|
3KB
|
111 lines
/*
File: pckcheck.c
Author: Graham Toal
Purpose: check correct spelling using dict.pck
Creation date: 22/06/90
Lastedit: 23/06/90 01:15:39
Description:
This can be expanded to be like the unix 'spell' command.
This demo file simply checks words passed on the command line.
note how it remembers words so that the second time it sees
them, it will call them correct. This is how you should
implement the 'ignore' feature of an interactive checker.
This version used the fast 'packed' data structure. This is
approximately 3 times faster, but not all utilities support
the packed versions. Also utilities which walk the trie are
considerably slower (say by a factor of 100) -- so chose when
to used 'dawg' and when to use 'pack'ed versions carefully!
*/
/* Manadatory header files */
#include <stdio.h>
#include "dawg.h"
#include "grope.h"
/*#define RCHECK*/ /* Enable for internal range checks... */
#include "utils.c"
/* Headers here as needed on per-program basis */
#include <ctype.h> /* eg, for isalpha() */
/* Spelling library utilities */
#include "init.c" /* Loading dicts */
#include "dyntrie.c" /* Creating dicts at run-time */
#include "print.c" /* Printing dicts */
#include "check.c" /* Checking words */
#include "locate.c" /* Finding words by their stems */
#include "soundex.c" /* Soundex algorithm for word-likeness comparison */
#include "similcmp.c" /* Closeness-metric for correction */
#include "correct.c" /* Hack code to attempt error correction (uses above) */
/* Let's be friendly to these guys... */
#ifdef SYS_MAC
/* To compile with THINK C 4.0, place all the relevant .h and .c
files in a folder. Then create a project which contains this main.c
and the libraries unix and ANSI.
*/
#include <unix.h>
#include <stdlib.h>
#include <console.h>
#endif
/* Your own header files go here, for instance:
#include "readword.h"
*/
int
#ifdef PROTOTYPES
main(int argc, char **argv)
#else
main(argc, argv)
int argc;
char **argv;
#endif
{
NODE PCCRAP *ptrie; /* precompiled dictionary (dict.pck) */
INDEX edges; /* size of above */
NODE PCCRAP *userdict; /* run-time dictionary, added to dynamically */
char *word;
int each;
#ifdef SYS_MAC
argc = ccommand(&argv); /* Mac users have my sympathy */
#endif
/* Your program goes here... */
if (argc == 1) {
fprintf(stderr, "usage: %s possibly mispeled wurdz\n", argv[0]);
exit(EXIT_ERROR);
}
if (!pack_init("", &ptrie, &edges)) exit(EXIT_ERROR);
if (!trie_new(&userdict)) exit(EXIT_ERROR);
for (each = 1; each < argc; each++) {
word = argv[each];
fprintf(stderr, "* %s:\n", word);
if (pack_check(ptrie, word) || dawg_check(userdict, word)) {
fprintf(stderr, "Correct\n");
} else {
fprintf(stderr, "Wrong\n");
(void)trie_add(&userdict, word);
}
if (each+1 != argc) fprintf(stderr, "\n");
}
exit(EXIT_OK);
}